package com.jet.merchant.gate;

import com.jet.merchant.domain.vo.ResourceVo;
import com.jet.merchant.service.IClerkResourceService;
import com.jet.core.result.ResultJson;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dcl
 * @date 2023-02-26 00:58:19
 */
@RestController
@RequestMapping("/gate/clerk/resource")
public class GateResourceController {

    private final IClerkResourceService clerkResourceService;

    public GateResourceController(IClerkResourceService clerkResourceService) {
        this.clerkResourceService = clerkResourceService;
    }

    /**
     * 获取菜单列表
     *
     * @param accountId
     * @return
     */
    @GetMapping("/list")
    @DeleteMapping
    public ResultJson list(@RequestHeader String accountId) {
        //根据accId获取到角色，根据角色获取到对应的menu
        List<ResourceVo> resourceList = clerkResourceService.findAllByAccountId(accountId);
        return ResultJson.ok(resourceList);
    }

    @GetMapping("/children-resources/{pid}")
    public ResultJson childrenResource(@PathVariable("pid") String pid) {
        List<ResourceVo> vo = clerkResourceService.findAllByPid(pid);
        return ResultJson.ok(vo);
    }
}
